package com.example.anew.journey.mynewjourney.firstchangelogic.firstChangeHistoricalRecordDateList.adpter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.anew.journey.mynewjourney.R;
import com.example.anew.journey.mynewjourney.firstchangelogic.firstChangeHistoricalRecordDateList.bean.HistoricalRecordListBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 杭州惟君医疗科技有限公司14
 * Created by 20433 on 2018/3/21
 *
 * @desc 东风山河绿，春已不折柳，繁花看不尽，处处惹人留
 * @desc 佛祖镇楼，bug辟容易
 */

public class HistoricalRecordDateListAdapter extends  RecyclerView.Adapter<HistoricalRecordDateListAdapter.ViewHolder> implements View.OnClickListener{
    private ChildItemAdapter mchildItemAdapter;
    private Context mcontxt ;
    private List<HistoricalRecordListBean.DataBean> mlist = new ArrayList<>();
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mcontxt =  parent.getContext();
        View view  =  View.inflate(parent.getContext(), R.layout.item_child_date_list,null);
        // 实例化viewholder
        ViewHolder viewHolder = new ViewHolder(view);
        view.setOnClickListener(this);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        String result = mlist.get(position).result;
        holder.tv_test_heart_rate.setText(result);
        String add_time = mlist.get(position).add_time;
        String[] arr = add_time.split(" ");
        String date = arr[0];
        String[] dir =  date.split("-");
        holder.tv_test_date.setText(dir[1]+"/"+dir[2]+" "+arr[1]);
        try {
            int state = Integer.parseInt(result);
            if(state < 120){
                holder.tv_test_date_state.setText("过慢");
                holder.tv_test_date_state.setTextColor(0xffFF9800);
            }else if(state > 160){
                holder.tv_test_date_state.setText("过快");
                holder.tv_test_date_state.setTextColor(0xffFF4800);
            }else{
                holder.tv_test_date_state.setText("正常");
                holder.tv_test_date_state.setTextColor(0xff323232);
            }
        } catch (NumberFormatException e) {
        }

    }

    public void addItem(List<HistoricalRecordListBean.DataBean> mdate){
        mlist.addAll(mdate);
        notifyDataSetChanged();
    }
    @Override
    public int getItemCount() {
        return mlist.size();
    }

    @Override
    public void onClick(View view) {

    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        private  TextView tv_test_heart_rate;
        private  TextView tv_test_date;
        private  TextView tv_test_date_state;
        public ViewHolder(View itemView) {
            super(itemView);
            tv_test_heart_rate = itemView.findViewById(R.id.item_child_date_list_tv_test_heart_rate);
            tv_test_date = itemView.findViewById(R.id.item_child_date_list_tv_test_date);
            tv_test_date_state = itemView.findViewById(R.id.item_child_date_list_tv_test_date_state);
        }
    }
}
